import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
    namespaced: true,
    state: {
        currentMenu: localStorage.getItem('current_menu')?JSON.parse(localStorage.getItem('current_menu')) : {},
        historyMenu: localStorage.getItem('history_menu')? JSON.parse(localStorage.getItem('history_menu')) : []
    },
    mutations: {
        updateHistoryMenu(state, data) {
            localStorage.setItem("history_menu", JSON.stringify(data));
            console.log(localStorage.getItem('history_menu'));
            state.historyMenu = data;
        },
        updateCurrentMenu(state, menu){
            localStorage.setItem("current_menu", JSON.stringify(menu));
            state.currentMenu = menu;
        },
        clearLogInfo(state){
            localStorage.setItem("history_menu", '[]');
            localStorage.setItem("current_menu", '{}');
        }
    }
});

export default store